package cn.ekuma.epos.datalogic.define.dao.sale;

import cn.ekuma.data.dao.BaseDAO;
import cn.ekuma.epos.db.table.pos.I_QuickProduct;

import com.openbravo.bean.AppUser;
import com.openbravo.bean.Product;
import com.openbravo.bean.sales.QuickProduct;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class QuickProductDAO extends BaseDAO<QuickProduct>{

	public QuickProductDAO(I_Session s) {
		super(s);
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "QUICK_PRODUCT",
                new Field[]{
                     new Field(I_QuickProduct.ID,Datas.STRING,Formats.STRING),
                     new Field(I_QuickProduct.TYPE,Datas.INT,Formats.INT),
                     new Field(I_QuickProduct.PRODUCTID,Datas.STRING,Formats.STRING,Product.class),
                     new Field(I_QuickProduct.PRODUCTATTR,Datas.STRING,Formats.STRING),
                     new Field(I_QuickProduct.REGUSERID,Datas.STRING,Formats.STRING),
                     new Field(I_QuickProduct.CURDATE,Datas.TIMESTAMP,Formats.TIMESTAMP),
                     new Field(I_QuickProduct.UNITS,Datas.DOUBLE,Formats.DOUBLE,AppUser.class)
                    },
                new int[]{0});
	}

	@Override
	public void writeInsertValues(DataWrite dp, QuickProduct obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setInt(2,obj.getType());
		dp.setString(3,obj.getProductId());
		dp.setString(4,obj.getProductAttr());
		dp.setString(5,obj.getRegUserId());
		dp.setTimestamp(6,obj.getCurDate());
		dp.setDouble(7,obj.getUnit());
		
	}

	@Override
	public Class getSuportClass() {
		return QuickProduct.class;
	}

	@Override
	public QuickProduct readValues(DataRead dr, QuickProduct obj)
			throws BasicException {
		if(obj==null)
			obj=new QuickProduct();
		obj.setId(dr.getString(1));
		obj.setType(dr.getInt(2));
		obj.setProductId(dr.getString(3));
		obj.setProductAttr(dr.getString(4));
		obj.setRegUserId(dr.getString(5));
		obj.setCurDate(dr.getTimestamp(6));
		obj.setUnit(dr.getDouble(7));
		return obj;
	}

}
